package com.caishi.lkx.exam.model;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.caishi.lkx.exam.ienum.type.ColumnPosition;
import com.caishi.lkx.exam.vo.ConfigVo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.zzw.common.entity.impl.BaseEntity;
import com.zzw.common.service.model.NameModel;
import com.zzw.common.service.model.base.SortModel;
import com.caishi.lkx.exam.ienum.type.ColumnType;

import com.caishi.lkx.order.IAssetsModel;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.List;

@Schema(title = "栏目")
@EqualsAndHashCode(callSuper = true)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName(value = "ex_column")
public class ColumnModel extends BaseEntity<ColumnModel> implements NameModel<ColumnModel, String>, SortModel<ColumnModel> , IAssetsModel<ColumnModel, String>{

    private String name;

    /**
     * 后台显示名称
     */
    private String serverName;

    /**
     * 科目id
     */
    private Long categoryId;


    private ColumnType type;

    private ColumnPosition position;

    private Integer sort;

    /** 所属机构id,可以为空，为空就是通用*/
    private Long groupId;

    /**
     * 栏目是否前端可见
     */
    @TableField("`show`")
    private Boolean show;

    @JsonIgnore
    private String cstkId;

    @Schema(title = "科目名")
    @TableField(exist = false)
    private String categoryName;

    @Schema(title = "是否已购买")
    @TableField(exist = false)
    private Boolean soldFlag;


    @TableField(exist = false)
    private Integer dataCount;

    @TableField(exist = false)
    private List<ConfigVo> configs;


    @Override
    public Long getPrice() {
        return null;
    }


    public static void main(String[] args) {
        String input1 = "db93d474-86d8-4d68-abff-f790ad4c4572";
        String input2 = "3489766419BX";

        String hash1 = generateMultiHash(input1);
        String hash2 = generateMultiHash(input2);

        System.out.println("Input1 Multi-Hash: " + hash1);
        System.out.println("Input2 Multi-Hash: " + hash2);
    }

    private static String generateMultiHash(String input) {
        try {
            MessageDigest digest = MessageDigest.getInstance("SHA-256");
            byte[] hash = digest.digest(input.getBytes(StandardCharsets.UTF_8));

            // 再次对初次哈希结果进行哈希计算
            ///hash = digest.digest(hash);

            StringBuilder hexString = new StringBuilder();
            for (byte b : hash) {
                String hex = Integer.toHexString(0xff & b);
                if (hex.length() == 1) hexString.append('0');
                hexString.append(hex);
            }
            return hexString.toString();
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }
}
